package com.alan.base.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.alan.base.R;

public class BTextView extends AppCompatTextView {

    protected int textType;

    public BTextView(Context context) {
        this(context, null);
    }

    public BTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    protected void init(Context context, @Nullable AttributeSet attrs) {
        if (attrs != null) {
            TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BTextView);
            textType = typedArray.getInteger(R.styleable.BTextView_text_type, 0);
            typedArray.recycle();
        }
        this.setIncludeFontPadding(false);
        setTextType(textType);
    }


    public void setTextType(@TextType int textType) {
        switch (textType) {
            case TextType.BOLD:
                this.setTypeface((Typeface) null, Typeface.BOLD);
                break;
            case TextType.ITALIC:
                this.setTypeface((Typeface) null, Typeface.ITALIC);
                break;
            case TextType.BOLD_ITALIC:
                this.setTypeface((Typeface) null, Typeface.BOLD_ITALIC);
                break;
            case TextType.NORMAL:
            default:
                this.setTypeface((Typeface) null, Typeface.NORMAL);
                break;
        }

    }

    @interface TextType {
        int NORMAL = 0;
        int BOLD = 1;
        int ITALIC = 2;
        int BOLD_ITALIC = 3;
    }

}
